#ifndef SERIALCONNECTION_H
#define SERIALCONNECTION_H

#include <QObject>
#include "qextserialport.h"
#include "QTimer"

// Define PortSettings here
#define     COMPORT             "COM1"
//#define     BAUDRATE            BAUD115200
#define     BAUDRATE            BAUD57600
//#define     BAUDRATE            BAUD921600
#define     FLOWCONTROL         FLOW_OFF
#define     PARITY              PAR_NONE
#define     DATABITS            DATA_8
#define     STOPBITS            STOP_1
#define     PORT_TIMEOUT        50

class SerialConnection : public QObject
{
    Q_OBJECT
public:
    explicit SerialConnection(QObject *parent = 0);
    virtual ~SerialConnection();

    virtual bool openPort(QString portName, BaudRateType baudrate);
    virtual void closePort();
    virtual void transmitMessage(QString msg);
    virtual void transmitMessage(char* buffer, int length);

    void setPollingInterval(int msec);

signals:
    void MsgReceived(QByteArray *msg);

public slots:

private slots:
    void receiveMsg();

private:
    QextSerialPort *port;
    QTimer timer_usart;    // For UART
    QByteArray input_buffer;
};

#endif // SERIALCONNECTION_H
